package com.wkf.calculator.utils;

import java.text.DecimalFormat;
import java.util.ArrayList;

//提取字符串中的数字与符号
public class GetScanInfos {
   public static ArrayList getScanInfos(String tmp) {
        ArrayList<ArrayList> totalBox = new ArrayList<ArrayList>();
        ArrayList<Float> numBox = new ArrayList<Float>();
        ArrayList<Character> symbolBox = new ArrayList<Character>(),
                             minusSign = new ArrayList<Character>(),
                             bracketsLeftBox = new ArrayList<Character>(),
                             bracketsRightBox = new ArrayList<Character>();
        String s = "";
        if (totalBox!= null){
            totalBox.clear();
            numBox.clear();
            symbolBox.clear();
        }
        int flag = -1;
        for (int i = 0; i < tmp.length(); i++) {
            char c = tmp.charAt(i);
            if (c == 46){
                flag = 0;
            }
            if (c == '+' || c == '-' || c == '*' || c == '/') {
                numBox.add(Float.parseFloat(s));
                s = "";
                symbolBox.add(c);

            } else if (c >= 48 && c <= 57) {
                s = s + c;
                if (flag == 0){
                    float f;
                    f = Float.parseFloat(s)/10;
                    s = String.valueOf(f);
                    flag = -1;
                }
                if (tmp.length() - i == 1) {
                    numBox.add(Float.parseFloat(s));
                }
            }

            totalBox.add(numBox);
            totalBox.add(symbolBox);
        }
        return totalBox;
    }
}
